Docker: fix usage of ENV variables that are not in .env.example

Variables that are usable but not present with default values in .env.example were located with this one-liner:

```
diff --changed-group-format='%<' --unchanged-group-format='' <(ack "ENV\[.(.+?).\]" --output='$1' -h app config lib db| sort | uniq) <(grep = .env.example | sed -e 's/^#\([^ ]\)/\1/' | grep -v -e '^#'| ack "(.+?)=" --output='$1'|sort)
```

Dominik Sander 7 years ago
parent
commit
d6e185f0f3
3 changed files with 18 additions and 5 deletions
  1. 1 1
      config/environments/production.rb
  2. 4 4
      db/seeds/seeder.rb
  3. 13 0
      docker/scripts/setup

+ 1 - 1
config/environments/production.rb

@@ -79,7 +79,7 @@ Huginn::Application.configure do
79 79
 
80 80
   config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
81 81
   config.action_mailer.asset_host = ENV['DOMAIN']
82
-  if ENV['ASSET_HOST']
82
+  if ENV['ASSET_HOST'].present?
83 83
     config.action_mailer.asset_host = ENV['ASSET_HOST']
84 84
   end
85 85
   config.action_mailer.perform_deliveries = true

+ 4 - 4
db/seeds/seeder.rb

@@ -1,14 +1,14 @@
1 1
 class Seeder
2 2
   def self.seed
3
-    user = User.find_or_initialize_by(:email => ENV['SEED_EMAIL'] || "admin@example.com")
3
+    user = User.find_or_initialize_by(:email => ENV['SEED_EMAIL'].presence || "admin@example.com")
4 4
     if user.persisted?
5 5
       puts "User with email '#{user.email}' already exists, not seeding."
6 6
       exit
7 7
     end
8 8
 
9
-    user.username = ENV['SEED_USERNAME'] || "admin"
10
-    user.password = ENV['SEED_PASSWORD'] || "password"
11
-    user.password_confirmation = ENV['SEED_PASSWORD'] || "password"
9
+    user.username = ENV['SEED_USERNAME'].presence || "admin"
10
+    user.password = ENV['SEED_PASSWORD'].presence || "password"
11
+    user.password_confirmation = ENV['SEED_PASSWORD'].presence || "password"
12 12
     user.invitation_code = User::INVITATION_CODES.first
13 13
     user.admin = true
14 14
     user.save!

+ 13 - 0
docker/scripts/setup

@@ -27,3 +27,16 @@ mv config/unicorn.rb.example config/unicorn.rb
27 27
 sed -ri 's/^listen .*$/listen ENV["PORT"]/' config/unicorn.rb
28 28
 sed -ri 's/^stderr_path.*$//' config/unicorn.rb
29 29
 sed -ri 's/^stdout_path.*$//' config/unicorn.rb
30
+
31
+# Add ENV variables to .env.example which are not present in it but usable
32
+cat >> /app/.env.example <<EOF
33
+ASSET_HOST=
34
+DEFAULT_SCENARIO_FILE=
35
+RAILS_SERVE_STATIC_FILES=
36
+SEED_EMAIL=
37
+SEED_PASSWORD=
38
+SEED_USERNAME=
39
+SMTP_OPENSSL_CA_FILE=
40
+SMTP_OPENSSL_CA_PATH=
41
+SMTP_OPENSSL_VERIFY_MODE=
42
+EOF